<template>
  <div class="category-card" @click="handleClick">
    <div class="category-icon">{{ iconText }}</div>
    <h3 class="category-name">{{ category.title }}</h3>
    <p class="course-count">{{ courseCount }} 门课程</p>
  </div>
</template>

<script>
export default {
  name: 'CategoryCard',
  props: {
    category: {
      type: Object,
      required: true
    },
    index: {
      type: Number,
      default: 0
    },
    courseCount: {
      type: Number,
      required: true
    }
  },
  computed: {
    iconText() {
      // 可以根据索引显示不同的图标或文本
      return this.index + 1
    }
  },
  methods: {
    handleClick() {
      // 触发父组件的事件来处理点击
      this.$emit('click', this.category.id)
    }
  }
}
</script>

<style scoped>
.category-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border: 1px solid #f0f0f0;
}

.category-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  border-color: #409eff;
}

.category-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background-color: #f0f9ff;
  color: #409eff;
  border-radius: 50%;
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 15px;
  transition: all 0.3s ease;
}

.category-card:hover .category-icon {
  background-color: #409eff;
  color: white;
}

.category-name {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: #303133;
}

.course-count {
  font-size: 14px;
  color: #909399;
  margin: 0;
}

@media (max-width: 768px) {
  .category-card {
    padding: 15px;
  }
  
  .category-icon {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .category-name {
    font-size: 16px;
  }
}
</style>